﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar.BusinessObjects;

namespace SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar
{
    public class ucAppointmentItem : ucContentControl
    {
        #region Dependency Variables
        private static readonly DependencyProperty StartDateProperty = DependencyProperty.Register("StartDate", typeof(DateTime), typeof(ucAppointmentItem), new PropertyMetadata(DateTime.Now, new PropertyChangedCallback(StartDate_Changed)));
        private static readonly DependencyProperty EndDateProperty = DependencyProperty.Register("EndDate", typeof(DateTime), typeof(ucAppointmentItem), new PropertyMetadata(DateTime.Now, new PropertyChangedCallback(EndDate_Changed)));
        private static readonly DependencyProperty StartTimeProperty = DependencyProperty.Register("StartTime", typeof(TimeSpan), typeof(ucAppointmentItem), new PropertyMetadata(DateTime.Now.TimeOfDay, new PropertyChangedCallback(StartTime_Changed)));
        private static readonly DependencyProperty EndTimeProperty = DependencyProperty.Register("EndTime", typeof(TimeSpan), typeof(ucAppointmentItem), new PropertyMetadata(DateTime.Now.TimeOfDay, new PropertyChangedCallback(EndTime_Changed)));
        private static readonly DependencyProperty StartDateDescProperty = DependencyProperty.Register("StartDateDesc", typeof(string), typeof(ucAppointmentItem), new PropertyMetadata("", new PropertyChangedCallback(StartDateDesc_Changed)));
        private static readonly DependencyProperty EndDateDescProperty = DependencyProperty.Register("EndDateDesc", typeof(string), typeof(ucAppointmentItem), new PropertyMetadata("", new PropertyChangedCallback(EndDateDesc_Changed)));
        private static readonly DependencyProperty StartTimeDescProperty = DependencyProperty.Register("StartTimeDesc", typeof(string), typeof(ucAppointmentItem), new PropertyMetadata("", new PropertyChangedCallback(StartTimeDesc_Changed)));
        private static readonly DependencyProperty EndTimeDescProperty = DependencyProperty.Register("EndTimeDesc", typeof(string), typeof(ucAppointmentItem), new PropertyMetadata("", new PropertyChangedCallback(EndTimeDesc_Changed)));
        private static readonly DependencyProperty DescProperty = DependencyProperty.Register("Desc", typeof(string), typeof(ucAppointmentItem), new PropertyMetadata("", new PropertyChangedCallback(Desc_Changed)));
        private static readonly DependencyProperty AppointmentBackgroundProperty = DependencyProperty.Register("AppointmentBackground", typeof(Brush), typeof(ucAppointmentItem), new PropertyMetadata(SLControlLibrary.Resources.Common.Utility.ConvertStringToColor("#10000000"), new PropertyChangedCallback(AppointmentBackground_Changed)));
        private static readonly DependencyProperty AppointmentForegroundProperty = DependencyProperty.Register("AppointmentForeground", typeof(Brush), typeof(ucAppointmentItem), new PropertyMetadata(new SolidColorBrush(Colors.White), new PropertyChangedCallback(AppointmentForeground_Changed)));
        private static readonly DependencyProperty AppointmentBorderBrushProperty = DependencyProperty.Register("AppointmentBorderBrush", typeof(Brush), typeof(ucAppointmentItem), new PropertyMetadata(SLControlLibrary.Resources.Common.Utility.ConvertStringToColor("#5D8CC9"), new PropertyChangedCallback(AppointmentBorderBrush_Changed)));
        private static readonly DependencyProperty AppointmentBorderThicknessProperty = DependencyProperty.Register("AppointmentBorderThickness", typeof(Thickness), typeof(ucAppointmentItem), new PropertyMetadata(new Thickness(1), new PropertyChangedCallback(AppointmentBorderThickness_Changed)));
        #endregion

        #region Dependency Properties
        public DateTime StartDate
        {
            get { return (DateTime)this.GetValue(StartDateProperty); }
            set { this.SetValue(StartDateProperty, value); }
        }
        public DateTime EndDate
        {
            get { return (DateTime)this.GetValue(EndDateProperty); }
            set { this.SetValue(EndDateProperty, value); }
        }
        public TimeSpan StartTime
        {
            get { return (TimeSpan)this.GetValue(StartTimeProperty); }
            set { this.SetValue(StartTimeProperty, value); }
        }
        public TimeSpan EndTime
        {
            get { return (TimeSpan)this.GetValue(EndTimeProperty); }
            set { this.SetValue(EndTimeProperty, value); }
        }
        public string StartDateDesc
        {
            get { return this.GetValue(StartDateDescProperty).ToString(); }
            set { this.SetValue(StartDateDescProperty, value); }
        }
        public string EndDateDesc
        {
            get { return this.GetValue(EndDateDescProperty).ToString(); }
            set { this.SetValue(EndDateDescProperty, value); }
        }
        public string StartTimeDesc
        {
            get { return this.GetValue(StartTimeDescProperty).ToString(); }
            set { this.SetValue(StartTimeDescProperty, value); }
        }
        public string EndTimeDesc
        {
            get { return this.GetValue(EndTimeDescProperty).ToString(); }
            set { this.SetValue(EndTimeDescProperty, value); }
        }
        public string Desc
        {
            get { return this.GetValue(DescProperty).ToString(); }
            set { this.SetValue(DescProperty, value); }
        }
        public Brush AppointmentBackground
        {
            get { return (Brush)this.GetValue(AppointmentBackgroundProperty); }
            set { this.SetValue(AppointmentBackgroundProperty, value); }
        }
        public Brush AppointmentForeground
        {
            get { return (Brush)this.GetValue(AppointmentForegroundProperty); }
            set { this.SetValue(AppointmentForegroundProperty, value); }
        }
        public Brush AppointmentBorderBrush
        {
            get { return (Brush)this.GetValue(AppointmentBorderBrushProperty); }
            set { this.SetValue(AppointmentBorderBrushProperty, value); }
        }
        public Thickness AppointmentBorderThickness
        {
            get { return (Thickness)this.GetValue(AppointmentBorderThicknessProperty); }
            set { this.SetValue(AppointmentBorderThicknessProperty, value); }
        }
        #endregion

        #region Dependency Events
        #region StartDate_Changed
        private static void StartDate_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnStartDate_Changed(e);
        }
        #endregion

        #region EndDate_Changed
        private static void EndDate_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnEndDate_Changed(e);
        }
        #endregion

        #region StartTime_Changed
        private static void StartTime_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnStartTime_Changed(e);
        }
        #endregion

        #region EndTime_Changed
        private static void EndTime_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnEndTime_Changed(e);
        }
        #endregion

        #region StartDateDesc_Changed
        private static void StartDateDesc_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnStartDateDesc_Changed(e);
        }
        #endregion

        #region EndDateDesc_Changed
        private static void EndDateDesc_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnEndDateDesc_Changed(e);
        }
        #endregion

        #region StartTimeDesc_Changed
        private static void StartTimeDesc_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnStartTimeDesc_Changed(e);
        }
        #endregion

        #region EndTimeDesc_Changed
        private static void EndTimeDesc_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnEndTimeDesc_Changed(e);
        }
        #endregion

        #region Desc_Changed
        private static void Desc_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnDesc_Changed(e);
        }
        #endregion

        #region AppointmentBackground_Changed
        private static void AppointmentBackground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnAppointmentBackground_Changed(e);
        }
        #endregion

        #region AppointmentForeground_Changed
        private static void AppointmentForeground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnAppointmentForeground_Changed(e);
        }
        #endregion

        #region AppointmentBorderBrush_Changed
        private static void AppointmentBorderBrush_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnAppointmentBorderBrush_Changed(e);
        }
        #endregion

        #region AppointmentBorderThickness_Changed
        private static void AppointmentBorderThickness_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucAppointmentItem).OnAppointmentBorderThickness_Changed(e);
        }
        #endregion
        #endregion

        #region Dependency Methods
        #region OnStartDate_Changed
        protected virtual void OnStartDate_Changed(DependencyPropertyChangedEventArgs e)
        {
            StartDate = (DateTime)e.NewValue;
            StartDateDesc = StartDate.ToShortDateString();
        }
        #endregion

        #region OnEndDate_Changed
        protected virtual void OnEndDate_Changed(DependencyPropertyChangedEventArgs e)
        {
            EndDate = (DateTime)e.NewValue;
            EndDateDesc = EndDate.ToShortDateString();
        }
        #endregion

        #region OnStartTime_Changed
        protected virtual void OnStartTime_Changed(DependencyPropertyChangedEventArgs e)
        {
            StartTime = (TimeSpan)e.NewValue;
            StartTimeDesc = string.Format("{0:t}", StartTime);
        }
        #endregion

        #region OnEndTime_Changed
        protected virtual void OnEndTime_Changed(DependencyPropertyChangedEventArgs e)
        {
            EndTime = (TimeSpan)e.NewValue;
            EndTimeDesc = string.Format("{0:t}", EndTime);
        }
        #endregion

        #region OnStartDateDesc_Changed
        protected virtual void OnStartDateDesc_Changed(DependencyPropertyChangedEventArgs e)
        {
            StartDateDesc = e.NewValue.ToString();
        }
        #endregion

        #region OnEndDateDesc_Changed
        protected virtual void OnEndDateDesc_Changed(DependencyPropertyChangedEventArgs e)
        {
            EndDateDesc = e.NewValue.ToString();
        }
        #endregion

        #region OnStartTimeDesc_Changed
        protected virtual void OnStartTimeDesc_Changed(DependencyPropertyChangedEventArgs e)
        {
            StartTimeDesc = e.NewValue.ToString();
        }
        #endregion

        #region OnEndTimeDesc_Changed
        protected virtual void OnEndTimeDesc_Changed(DependencyPropertyChangedEventArgs e)
        {
            EndTimeDesc = e.NewValue.ToString();
        }
        #endregion

        #region OnDesc_Changed
        protected virtual void OnDesc_Changed(DependencyPropertyChangedEventArgs e)
        {
            Desc = e.NewValue.ToString();
        }
        #endregion

        #region OnAppointmentBackground_Changed
        protected virtual void OnAppointmentBackground_Changed(DependencyPropertyChangedEventArgs e)
        {
            AppointmentBackground = (Brush)e.NewValue;
        }
        #endregion

        #region OnAppointmentForeground_Changed
        protected virtual void OnAppointmentForeground_Changed(DependencyPropertyChangedEventArgs e)
        {
            AppointmentForeground = (Brush)e.NewValue;
        }
        #endregion

        #region OnAppointmentBorderBrush_Changed
        protected virtual void OnAppointmentBorderBrush_Changed(DependencyPropertyChangedEventArgs e)
        {
            AppointmentBorderBrush = (Brush)e.NewValue;
        }
        #endregion

        #region OnAppointmentBorderThickness_Changed
        protected virtual void OnAppointmentBorderThickness_Changed(DependencyPropertyChangedEventArgs e)
        {
            AppointmentBorderThickness = (Thickness)e.NewValue;
        }
        #endregion
        #endregion

        #region Variables
        public AppointmentItemsPanel _Panel = null;
        #endregion

        #region Constructor
        public ucAppointmentItem(AppointmentItemsPanel _ParentPanel)
        {
            DefaultStyleKey = typeof(ucAppointmentItem);
            _Panel = _ParentPanel;
            base.Base_Resized += new EventHandler(ucAppointmentItem_Base_Resized);
        }
        #endregion

        #region Methods
        #region OnApplyTemplate
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            base.SetDraging(_Panel, false, true);
        }
        #endregion
        #endregion

        #region Events
        #region ucAppointmentItem_Base_Resized
        private void ucAppointmentItem_Base_Resized(object sender, EventArgs e)
        {
            Size NewSize = (Size)sender;
            this.Height = NewSize.Height;
            this.Width = NewSize.Width;
        }
        #endregion
        #endregion
    }
}
